package com.jindi.appuser.controller;

import com.jindi.appuser.common.EmptyUtil;
import com.jindi.appuser.common.ServerResponse;
import com.jindi.appuser.service.impl.AppInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * User: duanj
 * Date: 2018-07-10
 * Time: 15:22
 * Description:
 */
@RestController
@RequestMapping("info")
public class AppInfoController {

    @Autowired
    private AppInfoService appInfoService;

    @PostMapping("list")
    ServerResponse appInfoList(String type, String os){
        return appInfoService.appInfoList(type,os);
    }

    /**
     * 添加app
     * @param name
     * @param size
     * @param publishTime 发布时间
     * @param os 系统   (0--pc  1--安卓  2--ios)
     * @param downUrl
     * @param iconUrl 图片类型
     * @param connect 内容
     * @param mode 授权方式 ：付费版
     * @param type 软件类型(0--综合版  1--时时彩软件  2--赛车软件  3--快三软件 4--十一选五软件)
     * @return
     */
    @PostMapping("add")
    ServerResponse add(@RequestParam(value = "name",required = false)String name,
                       @RequestParam(value = "size",required = false)String size,
                       @RequestParam(value = "publishTime",required = false)String publishTime,
                       @RequestParam(value = "os",required = false)String os,
                       @RequestParam(value = "downUrl",required = false)String downUrl,
                       @RequestParam(value = "iconUrl",required = false)String iconUrl,
                       @RequestParam(value = "connect",required = false)String connect,
                       @RequestParam(value = "mode",required = false)String mode,
                       @RequestParam(value = "type",required = false)String type){
        if(EmptyUtil.isEmpty(name)|| EmptyUtil.isEmpty(size)|| EmptyUtil.isEmpty(publishTime)
                || EmptyUtil.isEmpty(os)|| EmptyUtil.isEmpty(downUrl)|| EmptyUtil.isEmpty(iconUrl)
                || EmptyUtil.isEmpty(mode)|| EmptyUtil.isEmpty(type)){
            return ServerResponse.createByErrorMessage("数据有误");
        }
        return appInfoService.addAppInfo(name,size,publishTime,downUrl,iconUrl,connect,mode,type,os);
    }

    /**
     * 修改app信息
     * @param id
     * @param name
     * @param size
     * @param publishTime
     * @param os
     * @param downUrl
     * @param iconUrl
     * @param connect
     * @param mode
     * @param type
     * @return
     */
    @PostMapping("update")
    ServerResponse update(@RequestParam(value = "id",required = false)Integer id ,
                          @RequestParam(value = "name",required = false)String name,
                          @RequestParam(value = "size",required = false)String size,
                          @RequestParam(value = "publishTime",required = false)String publishTime,
                          @RequestParam(value = "os",required = false)String os,
                          @RequestParam(value = "downUrl",required = false)String downUrl,
                          @RequestParam(value = "iconUrl",required = false)String iconUrl,
                          @RequestParam(value = "connect",required = false)String connect,
                          @RequestParam(value = "mode",required = false)String mode,
                          @RequestParam(value = "type",required = false)String type){

        return appInfoService.updateAppInfoById(id,name,size,publishTime,downUrl,iconUrl,connect,mode,type,os);
    }

    /**
     * 删除选中app
     * @param id
     * @return
     */
    @PostMapping("del")
    ServerResponse del(@RequestParam(value = "id",required = false)Integer id){
        return appInfoService.delAppInfoById(id);
    }

    /**
     * 查看app详细信息
     * @param id
     * @return
     */
    @PostMapping("info")
    ServerResponse info(@RequestParam(value = "id",required = false)Integer id){
        return appInfoService.getAppInfoById(id);
    }

}
